$(document).ready(function () {
    getProvinces()
});

function getProvinces() {
    var loadIndex = layer.load(2);
    let datas = {
        url: '/api/region/provinces',
        http_type: 'POST',
        datas: {
            "country_id":'16'
        }
    }
    wxx.HttpReqeust(datas, function (response) {
        layer.close(loadIndex)
        if (response.code == 1) {
            for (let i = 0; i < response.data.length; i++) {
                for (let j = 0; j < response.data[i].children.length; j++) {
                    let tr = $("<tr></tr>")
                    let td_1 = $("<td class='national_name'></td>")
                    $(td_1).text(response.data[i].label)
                    let td_2 = $("<td></td>")
                    $(td_2).text(response.data[i].children[j].n)
                    let td_3 = $("<td></td>")
                    $(td_3).text(response.data[i].children[j].label)
                    $(tr).append(td_1)
                    $(tr).append(td_2)
                    $(tr).append(td_3)
                    $("#provinces_table").append(tr)
                }
            }
            $("#provinces_table").rowspan(0);
        } else {
            layer.alert(response.msg, {title: '温馨提示'});
        }
    });
}

/**
 * jquery合并单元格
 * @param colIdx
 * @returns {*}
 */
jQuery.fn.rowspan = function  (colIdx) {
    return this.each(function(){
        var that;
        $('tr', this).each(function(row) {
            $('td:eq('+colIdx+')', this).filter(':visible').each(function(col) {
                if (that!=null && $(this).html() == $(that).html()) {
                    rowspan = $(that).attr("rowSpan");
                    if (rowspan == undefined) {
                        $(that).attr("rowSpan",1);
                        rowspan = $(that).attr("rowSpan"); }
                    rowspan = Number(rowspan)+1;
                    $(that).attr("rowSpan",rowspan);
                    $(this).hide();
                } else {
                    that = this;
                }
            });
        });
    });
}


